package com.kfm.hotel.interceptor;

import com.kfm.hotel.util.Contains;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object attribute = request.getSession().getAttribute(Contains.LOGIN_USER);

        if (attribute == null){
            // 没登录
            response.sendRedirect("/");
            return false;
        }

        return true;

    }
}
